package mahjong.auto.com.automahjong;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

import mahjong.auto.com.os.BoardInfo;
import mahjong.auto.com.os.EnumMahjong;
import mahjong.auto.com.os.Mahjong;

/**
 * Created by heqian on 17-8-14.
 */

public class InfoActivity extends FloatActivity implements View.OnClickListener, Mahjong.MahjongCall {

    private final CheckBox checkBox;
    private final App app;
    private String mText;


    public InfoActivity(Context context) {
        super(context, R.layout.activity_float);
        app = (App) context.getApplicationContext();

        checkBox = (CheckBox) findViewById(R.id.button_box);
        checkBox.setOnClickListener(this);

        Mahjong.setCall(this);
    }

    private final Handler mHandler = new Handler() {
        @Override
        public void dispatchMessage(Message msg) {
            super.dispatchMessage(msg);
            ((TextView) findViewById(R.id.text_show)).setText(mText);
        }
    };

    @Override
    public void onClick(View v) {
        if (R.id.button_box == v.getId()) {
            if (R.id.button_box == v.getId()) {
                if (checkBox.isChecked()) {
                    app.getHandler().sendEmptyMessage(EnumPublic.Start.ordinal());
                } else {
                    app.getHandler().sendEmptyMessage(EnumPublic.Stop.ordinal());
                }
            }
        }
    }


    @Override
    public boolean simulateClick(int x, int y) {
        return false;
    }

    @Override
    public void info(BoardInfo info) {
        mText = " 下家(" + info.getDown().ismIsDealer() + ")" + info.getDown().getLackBoard().toString() + ":";
        for (EnumMahjong item : info.getDown().getOpen()) {
            mText += item.toString() + ",";
        }
        mText += "\n";
        for (EnumMahjong item : info.getDown().getOut()) {
            mText += item.toString() + ",";
        }

        mText += "\n对家(" + info.getTop().ismIsDealer() + ")" + info.getTop().getLackBoard().toString() + ":";
        for (EnumMahjong item : info.getTop().getOpen()) {
            mText += item.toString() + ",";
        }
        mText += "\n";
        for (EnumMahjong item : info.getTop().getOut()) {
            mText += item.toString() + ",";
        }

        mText += "\n上家(" + info.getUp().ismIsDealer() + ")" + info.getUp().getLackBoard().toString() + ":";
        for (EnumMahjong item : info.getUp().getOpen()) {
            mText += item.toString() + ",";
        }
        mText += "\n";
        for (EnumMahjong item : info.getUp().getOut()) {
            mText += item.toString() + ",";
        }

        mText += "\n自己(" + info.getMe().ismIsDealer() + ")" + info.getMe().getLackBoard().toString() + ":";
        for (EnumMahjong item : info.getMe().getOpen()) {
            mText += item.toString() + ",";
        }
        mText += "\n";
        for (EnumMahjong item : info.getMe().getOut()) {
            mText += item.toString() + ",";
        }
        mText += "\n";
        for (EnumMahjong item : info.getMe().getBoard()) {
            mText += item.toString() + ",";
        }
        mHandler.sendEmptyMessage(0);
    }

}
